<template>
  <div class="page"
       :style="{width:width+'px',height:height+'px'}">
    <div class="page__bd">
      <div class="weui-tab">
        <div class="weui-tab__panel"
             v-if="questionList.length">
          <div class="weui-tab__content"
               :hidden="activeIndexId != 0">
            <div class="blank"></div>
            <div v-for="(item,index) in arr2"
                 :key=index>
              {{item.right}}
            </div>
            <div class="question"
                 v-for="(item2,index2) in questionList"
                 :key=index2>
              <div class="questionNum">
                第{{index2+1}}题
              </div>
              <div class="questionContent">
                <div class="questionTitle">
                  {{item2.question}}
                </div>
                <div class="questionAnswer">
                  <div v-for="(value,key,index2) in questionList.length&&answer_list"
                       :key=key>
                    <p @click.stop="choise(index,key,index2)">
                      <span>{{options[key]}}</span>
                      {{value}}
                    </p>
                  </div>
                </div>
              </div>
              <div class="analyseAnswer">
                <p>正确答案：{{questionList[index2].answerkey}}</p>
                <p>所在章节：{{questionList[index2].location}} </p>
                <p>知识点： {{questionList[index2].point}} </p>
                <p>答案解析：</p>
                <p>{{questionList[index2].analyse}}</p>
              </div>
            </div>
          </div>
        </div>
        <div v-else
             class="noError">
          <p>
            <span> 哇,你也太厉害了,一道题都没有做错!!!</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      tabs: ['单选题', '多选题', '判断题', '填空题'],
      activeIndexId: 0,
      questionList: [],
      arr2: [],
      options: ['A', 'B', 'C', 'D'],
      noData: false
    }
  },
  computed: {
    ...mapState({
      examPaper: state => state.examPaper,
      randomRecord: state => state.randomRecord,
      userInfo: state => state.userInfo
    }),
    answer_list () {
      let that = this
      for (let i in that.questionList) {
        if (that.questionList[i].answerlist) {
          return Object.keys(that.questionList[i].answerlist).map(key => that.questionList[i].answerlist[key]).sort((a, b) => {
            return a.localeCompare(b)
          })
        } else {
          return Object.keys(that.questionList[i].answer_list).map(key => that.questionList[i].answer_list[key]).sort((a, b) => {
            return a.localeCompare(b)
          })
        }
      }

      // return that.questionList.length && Object.keys(that.questionList[that.index2].answerlist).map(key => that.questionList[that.index2].answerlist[key]).sort((a, b) => {
      //   return a.localeCompare(b)
      // })
    },
    navbarSliderClass () {
      if (Number(this.activeIndexId) === 0) {
        return 'weui-navbar__slider_0'
      }
      if (Number(this.activeIndexId) === 1) {
        return 'weui-navbar__slider_1'
      }
      if (Number(this.activeIndexId) === 2) {
        return 'weui-navbar__slider_2'
      }
      if (Number(this.activeIndexId) === 3) {
        return 'weui-navbar__slider_3'
      }
    }
  },
  methods: {
    tabClick (e) {
      if (Number(e)) {
        this.activeIndexId = 0
      } else {
        this.activeIndexId = e.currentTarget.id
      }
      console.log(e.currentTarget.id)
      wx.showLoading({
        title: '加载中',
        success () {
          wx.hideLoading()
        }
      })
    },
    init () {
      let that = this
      this.questionList = []
      wx.showLoading({
        title: '加载中'
      })
      this.$http.post('https://dati.co-links.com/operat/red_error/', {
        userid: that.userid || that.$mp.query.userid,
        recordingid: that.$mp.query.recordingid
      }).then((res) => {
        if (res.data.code === '0000') {
          wx.hideLoading()
          that.questionList = res.data.data
        }
      })
    }
  },
  mounted () {
    this.userid = this.userInfo.userid
    if (this.$mp.query.recordingid >= 0) {
      this.init()
    } else {
      var temp = this.randomRecord.paperTest
      var arr = []
      for (var i = 0; i < temp.length; i++) {
        console.log(temp[i])
      }
      console.log(temp)
      for (let i = 0; i < temp.length; i++) {
        if (temp[i].activeIndex * 1 === temp[i].rightNum * 1) {
          console.log(i)
          // temp.splice(i, 1)
        } else {
          arr.push(temp[i])
        }
      }

      this.questionList = arr
    }
  }
}
</script>
<style lang="stylus" scoped>
.page {
  background: #f7f7f7;
  height: 100%;
}

.noError {
  height: 100%;
  position: relative;
}

.noError p {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 700rpx;
  height: 80rpx;
  text-align: center;

  span {
    font-size: 34rpx;
    color: #333;
  }
}

.page__bd {
  background: white;
  height: 100%;
}

.weui-navbar__slider_0 {
  left: 0rpx;
  transform: translateX(50%);
}

.weui-navbar__slider_1 {
  left: 25%;
  transform: translateX(50%);
}

.weui-navbar__slider_2 {
  left: 50%;
  transform: translateX(50%);
}

.weui-navbar__slider_3 {
  left: 75%;
  transform: translateX(50%);
}

.weui-navbar__slider {
  width: 100rpx;
}

.weui-navbar {
  border-bottom: 0;
  background: white;
}

.blank {
  height: 20rpx;
  background: #f7f7f7;
}

.question {
  padding: 0 32rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
  background: white;

  .questionNum {
    font-size: 30rpx;
    color: #333;
    height: 98rpx;
    line-height: 98rpx;
    border-bottom: 2rpx solid #e6e6e6;
  }

  .questionTitle {
    font-size: 32rpx;
    color: #333333;
    padding: 20rpx 0;
  }
}

.questionContent {
  padding-bottom: 30rpx;
}

.questionAnswer {
  p {
    font-size: 32rpx;
    color: #666666;
    padding: 18rpx 0;
    padding-left: 30rpx;

    span {
      display: inline-block;
      width: 48rpx;
      height: 48rpx;
      border-radius: 50%;
      margin-right: 30rpx;
      border: 1px solid #a5a5a5;
      text-align: center;
      line-height: 48rpx;
    }
  }

  .right {
    color: #00cc76;

    span {
      background: #00cc76;
      color: #fff;
      border: 1px solid #00cc76;
    }
  }

  .wrong {
    color: #ef5152;

    p {
      color: #ef5152;
    }

    span {
      background: #ef5152;
      color: #fff;
      border: 1px solid #ef5152;
    }
  }
}

.analyseAnswer {
  padding: 20rpx 22rpx;
  background: #ebebeb;
  font-size: 32rpx;
  color: #333333;
  border-radius: 12rpx;
  -webkit-border-radius: 12rpx;
  margin-bottom: 20rpx;

  p {
    line-height: 60rpx;
  }

  p:last-child {
    font-size: 28rpx;
  }
}

.weui-tab__panel {
  background: #f7f7f7;
  padding-top: 0;
}
</style>
